## fuqiyang
##
## 2017-05-08


## global variable, also can define in "make xxx=xxx"
##

url ?= "https://updatetencent.webrtc.win/tencent"


ifeq (${default_version},)
override _version:=_${version}
else
override version:=${default_version}
override _version:=
endif
$(info "version: ${version}, _version: ${_version}")

update_data_dirs_name=$(patsubst update-data/%/,%,$(shell ls -d update-data/*/))

targz_files=$(shell ls *tar.gz)

json_files=$(shell ls *json)

raw_files=$(shell ls *json.raw)

## function
##
define printf_color
	@echo "\033[33m${1}\033[0m"
endef


## target
##
all : clean pack_update_data json_raw_file_create json_raw_file_show json_platform_file_create 
	$(call printf_color,"finish...")


help :
	$(call printf_color,"[help]")
	@echo "make [host=? signal_ws=? signal_wss=? version=? url=?] [upload_to_server upload_to_oschina]"


clean:
	@-rm -rf *json*
	@-rm -rf *tar.gz
	make -C ./update-data clean


pack_update_data :
	$(call printf_color,"[pack_update_data]")
	make -C ./update-data _version=${_version}


json_raw_file_create :
	$(call printf_color,"[json_raw_file_create]")
	for dir in ${update_data_dirs_name};												\
	do																\
		echo "{" > $${dir}${_version}.json.raw;										\
		echo "\"version\": \"$(version)\"," >> $${dir}${_version}.json.raw;							\
		echo "\"url\": \"$(url)/$${dir}${_version}.tar.gz\"," >> $${dir}${_version}.json.raw;					\
		echo "\"md5\": \"$$(md5sum $${dir}${_version}.tar.gz | awk '{print $$1}')\"" >> $${dir}${_version}.json.raw;		\
		echo "}" >> $${dir}${_version}.json.raw;										\
	done


json_raw_file_show :
	$(call printf_color,"[json_raw_file_show]")
	for dir in ${update_data_dirs_name};									\
	do													\
		cat $${dir}${_version}.json.raw;								\
	done
	

json_platform_file_create :
	$(call printf_color,"[json_platform_file_create]")
	for dir in ${update_data_dirs_name};									\
	do													\
		base64  ./$${dir}${_version}.json.raw | tr -d  '\n' > ./$${dir}${_version}.json;		\
	done


.PHONY : json_raw_file_create json_raw_file_show json_platform_file_create pack_update_data





